<template>
  <el-container class="container">
    <el-header class="header">
      <el-row>
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <h3>黑马程序员</h3>
          </div>
        </el-col>
        <el-col :span="18" class="middle">
          <div class="grid-content bg-purple-light">
            <h3>电商管理平台</h3>
          </div>
        </el-col>
        <el-col :span="2">
          <div class="grid-content bg-purple"></div><a class="loginout" @click.prevent ="loginout()" href="#">退出</a>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside class="aside" width="200px">
        <el-menu :router="true" :unique-opened = "true">
          <el-submenu :index="item.order+''" v-for="(item,key) in menu" :key ="key">
            <template slot="title">
              <i class="el-icon-office-building"></i>
              <span>{{item.authName}}</span>
            </template>
            <el-menu-item :index="item1.path" v-for="(item1,key) in item.children" :key ="key">
              <i class="el-icon-location"></i>
              <span>{{item1.authName}}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>

      </el-aside>
      <el-main class="main">
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data () {
    return {
      menu: []
    }
  },
  created () {
    this.getMenu()
  },
  methods: {
    async getMenu () {
      const res = await this.$http.get('menus')
      this.menu = res.data.data
      console.log(this.menu)
    },
    loginout () {
      this.$message.success('退出成功')
      this.$router.push({
        name: 'login'
      })
    }
  }
}
</script>

<style>
  .container {
    height: 100%;
  }

  .header {
    background-color: #b3c0d1;
  }

  .aside {
    background-color: #d3dce6;
  }

  .main {
    background-color: #e9eef3;
  }

  .middle {
    text-align: center;
  }

  .loginout {
    line-height: 60px;
    text-decoration: none;
  }
</style>
